from pdf2docx import Converter

def pdf2word(file_path):
    try:
        file_type = file_path.split('.')[1]
        if file_type == 'pdf':
            docx_name = file_path.replace(".pdf", ".docx")
            cv = Converter(file_path)
            cv.convert(docx_name)
            print(f'PDF文件转换成功！,在{docx_name}')
        else:
            print('请选择pdf格式的文件！')
    except:
        print('pdf文件转换失败，请确认文件并重试！')
 
if __name__ == '__main__':
    path = input('请输入pdf格式的文件路径:')
    pdf2word(path)
    input()